/**
 * 
 */
package com.gr.experimental.model.impl.distr.operators;


/**
 * @author Karol Banczyk
 *
 */
public class NumericNegationOperator extends AbstractUnaryOperator {

	enum NumberType {
		DOUBLE,
		LONG,
		INT
	}
	
	NumberType numberType;
	
	/**
	 * @param type
	 */
	public NumericNegationOperator(Class<?> type) {
		super(Utils.assertNumberType(type));
		if (Double.class.isAssignableFrom(type)) {
			numberType = NumberType.DOUBLE;
		}
		if (Long.class.isAssignableFrom(type)) {
			numberType = NumberType.LONG;
		}
		if (Integer.class.isAssignableFrom(type)) {
			numberType = NumberType.INT;
		}
	}

	/**
	 * {@inheritDoc}
	 * @see com.gr.experimental.model.impl.distr.operators.UnaryOperator#op(java.lang.Object)
	 */
	@Override
	public Object op(Object arg) {
		Number n = (Number) arg;
		switch(numberType) {
		case DOUBLE: return n.doubleValue() * (-1);
		case LONG: return n.longValue() * (-1);
		case INT: return n.intValue() * (-1);
		}
		throw new AssertionError("Object " + arg + " of unknown type");
	}

}
